﻿using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using XieCan.Core;
using XieCan.Core.Entity;
using XieCan.Core.DTO;
using XieCan.Core.Repository;
using XieCan.Core.Api;
using XieCan.Core.IReposity;
using XieCan.Core.Swigger;

namespace XieCan.Core.Api.Controllers
{
  /// <summary>
  /// 地址管理
  /// </summary>
  /// <param name="loggerFactory">日志工厂</param>
  /// <param name="repository">数据仓储</param>
  /// <param name="mapper">数据映射</param>
  [ApiRoute(ApiVersion.V1)]
  public partial class AddressController(ILoggerFactory loggerFactory, IAddressRepository repository, IMapper mapper, IAccountRepository accountRepository)
    : ApiControllerBase<AddressController, AddressEntity, AddressCreateModel, AddressUpdateModel, AddressListModel, AddressSingleModel>(loggerFactory, repository, mapper)
  {
    /// <inheritdoc/>
    public override async Task<OperateResult<bool>> Post([FromBody] AddressCreateModel model)
    {
      var user = await accountRepository.GetAsync(model.UserId);
      if (user.Data == null)
      {
        return OperateResult<bool>.Failed("所属用户不存在");
      }
      return await base.Post(model);
    }
  }
}
